#include <iostream>
#include <gtest/gtest.h>
#include <unordered_map>


class MyEnviroment : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        std::cout << "单元测试执行前的环境初始化" << std::endl;
    }

    virtual void TearDown() override
    {
        std::cout << "单元测试执行后的环境清理" << std::endl;
    }
};

TEST(MyEnviroment, test1)
{
    std::cout << "测试1" << std::endl;
}

TEST(MyEnviroment, test2)
{
    std::cout << "测试2" << std::endl;
}

std::unordered_map<std::string, std::string> mymap;
class MyMap : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        std::cout << "单元测试执行前的环境初始化" << std::endl;
        mymap.insert({"hello", "你好"});
        mymap.insert({"你好", "hello"});
    }

    virtual void TearDown() override
    {
        std::cout << "单元测试执行后的环境清理" << std::endl;
        mymap.clear();
    }
};

TEST(MyMap, test1)
{
    ASSERT_EQ(mymap.size(), 2);
    mymap.erase("hello");
}

TEST(MyMap, test2)
{
    ASSERT_EQ(mymap.size(), 2);
}

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MyEnviroment);
    testing::AddGlobalTestEnvironment(new MyMap);

    RUN_ALL_TESTS();

    return 0;
}